<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Content_model extends CI_Model{
		
		function __construct()
		{
			parent::__construct();
			$this->table = 'content';
			$this->cate_table = 'content_category';
			
		}
		
		function Get($id = '')
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where('id' , $id)
			  ->get()
			  ->row_array();
		}
		function getByCode($id = '')
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where('id' , $id)
			  ->get()
			  ->row_array();
		}
		//取出数量
		public function getCount($where,$like=''){
			$this->db->select('*');
			$this->db->from($this->table);
			$this->db->where($where);
			if($like){
				$this->db->like($this->table.'.title',$like);
			}
			$this->db->order_by("id", "desc");
			$query = $this->db->get();
			return $query->num_rows();
		}
		//取出列表
		public function getList($where,$page,$limit,$like)
	    {
			$this->db->select($this->table.'.*,'.$this->cate_table.'.title as cate_name');
			$this->db->from($this->table);
			$this->db->join($this->cate_table, $this->table.'.cate_id = '.$this->cate_table.'.id', 'left');
			if($like){
				$this->db->like($this->table.'.title',$like);
			}
			$this->db->where($where);
			$this->db->order_by("id", "desc");
			$this->db->limit($limit, $page);
			$query = $this->db->get();
			return $query->result_array(); 
	    }
		
		//插入数据
		function insert($data)
		{
			$this->db->insert($this->table, $data);
			return $this->db->affected_rows();
		}
		//更新数据
		function update($data,$id)
		{
			return $this->db->where('id',$id)->update($this->table, $data);
		}
		//设置状态
		function setstatus($status,$ids)
		{
			return $this->db->where_in('id',$ids)->update($this->table, array('status'=>$status));
		}
		//删除数据
		function dalete($delid)
		{	
			$this->db->where('id',$delid);
			$this->db->delete($this->table);
			return $this->db->affected_rows();
		}
		
		
	}